package com.smxy.mall.service.impl;

import com.smxy.mall.dao.VipDao;
import com.smxy.mall.entity.Vip;
import com.smxy.mall.model.request.VipReq;
import com.smxy.mall.service.VipService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class VipServiceImpl implements VipService {
    @Resource
    private VipDao vipDao;

    @Override
    public List<Vip> list() {
        return vipDao.findAll();
    }

    @Override
    public Vip findById(Integer id) {
        return vipDao.findById(id);
    }

    @Override
    public Vip save(VipReq vipReq) {
        Vip vip = new Vip();
        vip.setName(vipReq.getName());
        vip.setTitle(vipReq.getTitle());
        vip.setMoney(vipReq.getMoney());
        vip.setPresentMoney(vipReq.getPresentMoney());
        vip.setRule(vipReq.getRule());
        vip.setImg(vipReq.getImg());
        if(!StringUtils.isEmpty(vipReq.getId())){
            vip.setId(vipReq.getId());
        }
        return vipDao.save(vip);
    }
}
